package test;



import com.sleepycat.db.DatabaseException;

import fr.cephb.joperon.core.Fid;
import fr.cephb.joperon.core.Operon;
import fr.cephb.joperon.tool.OperonFactory;
import fr.cephb.lang.Endian;

/*
 
shows how to use an iterator to list the values of a database

 */
public class Example020
	{
	public static void main(String[] args)
		{
		Endian.setDefault(Endian.CNG);
		Operon operon=null;
		OperonFactory factory = null;
		try {
			operon= Operon.newInstance();
			//open a factory  with the default assembly
			factory= new OperonFactory(operon);
			
			
			if(!factory.isSnpIdsExists())
				{
				throw new DatabaseException("no database for this assembly "+factory.getAssembly());
				}
			
			/* the operon factory contains most of the database in operon
			 * each database is automatically open and closed */
			for(Fid fid: factory.getSnpIds().getFids("rs25"))
				{
				System.out.println(fid.getChromosome()+" "+fid.getPosition());
				}
			
			} 
		catch (Exception e) {
			//print error if any
			e.printStackTrace();
			}
		finally
			{
			//ALWAYS close the factory
			if(factory!=null) factory.close();
			//ALWAYS close operon
			if(operon!=null) operon.safeClose();
			}
		}
	}
